﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using TerminalTick.Models;

namespace TerminalTick.SignalR
{
    public class TerminalTicker
    {
        private static readonly Lazy<TerminalTicker> _instance =
            new Lazy<TerminalTicker>(() => 
                new TerminalTicker(GlobalHost.ConnectionManager.GetHubContext<TerminalHub>().Clients));
        
        private TerminalTicker(IHubConnectionContext clients)
        {
            this.Clients = clients;
        }

        public IHubConnectionContext Clients { get; set; }

        public static TerminalTicker Instance
        {
            get { return _instance.Value; }
        }

        public void Broadcast(int x, int y, BroadcastMessage message)
        {
            Clients.All.broadcast(x, y, message);
        }
    }
}